package com.offcn.test;

import com.offcn.bean.User;
import com.offcn.bean.User2;
import com.offcn.mapper.UserMapper;
import com.offcn.utils.MybatisUtils;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;

public class Demo02 {

    static Logger logger = Logger.getLogger(Demo02.class);
    // 分页
    @Test
    public void test() {

        SqlSession sqlSession = MybatisUtils.getSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        logger.info("分页查询用户：");
        HashMap<String,Integer> hashMap = new HashMap<String,Integer>();
        int currentPage=1; // 当前页
        int pageSize = 3; // 每页显示数据的个数
        hashMap.put("startIndex",(currentPage-1)*pageSize);
        hashMap.put("pageSize",pageSize);
        List<User2> user2List = mapper.selectUserPage(hashMap);
        for(User2 user:user2List){
            System.out.println(user);
        }


    }

    // 使用注解式
//    @Test
//    public void test2() {
//        SqlSession sqlSession = MybatisUtils.getSession();
//        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
//        User user = mapper.getUserByIdNote(8);
//        System.out.println(user.toString());
//
//    }

}
